﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using System.Drawing;

namespace AzureGames.Data.InMemory
{
    public class ResourceRepository : IResourceRepository
    {
        public Model.Resource GetResource(Guid ResourceID)
        {
            switch (ResourceID.ToString().ToUpper())
            {
                case "FAF03F72-024B-4651-8A9D-C84807CF7F61":
                    return BuildResource(ResourceID, "Amazons.css", "text/css", Resources.AmazonsCSS, null);
                case "5952650D-1E18-43F6-9134-1A4AF7315D23":
                    return BuildResource(ResourceID, "class.js", "text/javascript", Resources._class, null);
                case "C80EF4D7-86E9-4332-9238-58D14015A6DF":
                    return BuildResource(ResourceID, "AzureGames.js", "text/javascript", Resources.AzureGames, new DateTime(2012, 11, 19));
                case "38793EDF-2EF9-4422-A37D-E960CC811C71":
                    return BuildResource(ResourceID, "GameBoard.js", "text/javascript", Resources.GameBoard, null);
                case "B3739128-ECB8-4524-961F-E1A66D154A79":
                    return BuildResource(ResourceID, "Move.js", "text/javascript", Resources.Move, null);
                case "B9D3E9C5-A1CD-4AB1-92C7-E84A692C9916":
                    return BuildResource(ResourceID, "MinMaxAI.js", "text/javascript", Resources.MinMaxAI, null);
                case "6B7CE3B4-695A-46F0-A5B8-382F86BA63BE":
                    return BuildResource(ResourceID, "AmazonsBoard.js", "text/javascript", Resources.AmazonsBoard, null);
                case "46E475BF-22AD-463E-A326-A9C2F90FA391":
                    return BuildResource(ResourceID, "AmazonsMove.js", "text/javascript", Resources.AmazonsMove, null);
                case "0525E0E0-5F6B-451F-B116-728E2DE4167D":
                    return BuildResource(ResourceID, "Amazons.js", "text/javascript", Resources.Amazons, null);
                case "116D6138-5473-48BC-ACA8-D112C2951AD4":
                    return BuildResource(ResourceID, "Blue-Mushroom-64.png", "image/jpeg", Resources.Blue_Mushroom_64, null);
                case "AE907743-FCDA-4D9D-AE1F-B6E75E34A647":
                    return BuildResource(ResourceID, "Dragon.png", "image/jpeg", Resources.Dragon, null);
                case "A4F5F1AC-43E0-4A39-8D86-1E510465837F":
                    return BuildResource(ResourceID, "Gnome nerd.png", "image/jpeg", Resources.Gnome_nerd, null);
                case "ED517214-138F-4D22-AF4F-DA3BBE1919D2":
                    return BuildResource(ResourceID, "Pink-Mushroom-64.png", "image/jpeg", Resources.Pink_Mushroom_64, null);
                case "C4A9BF33-42DA-4976-ACFC-B3DB3DB3ECB3":
                    return BuildResource(ResourceID, "Purple-Mushroom-64.png", "image/jpeg", Resources.Purple_Mushroom_64, null);
                case "CA9DB050-8DC7-4CDC-819F-9C185E724183":
                    return BuildResource(ResourceID, "soup can2.png", "image/jpeg", Resources.soup_can2, null);
                case "7218C75D-2AE5-4A8F-B6FF-E45D5017723F":
                    return BuildResource(ResourceID, "penguin.png", "image/jpeg", Resources.penguin, null);
                case "3ED2B825-CE5C-41B1-A139-AB517F55B87E":
                    return BuildResource(ResourceID, "Triangle head.png", "image/jpeg", Resources.Triangle_head, null);
                case "3189F574-329B-45A3-A5DA-23A51974E045":
                    return BuildResource(ResourceID, "Woman3.png", "image/jpeg", Resources.Woman3, null);    
                case "31486A69-09BF-4BF9-A2CA-38B15AA7A808":
                    return BuildResource(ResourceID, "AmazonsGameImage", "image/jpeg", Resources.AmazonsGameImage, null);
                case "00000000-0000-0000-0000-000000000000":
                    return BuildResource(ResourceID, "Game", "image/jpeg", Resources.DefaultGame, null);
                case "87C981C4-07FC-42D3-97EE-AB0B4676CEA0":
                    return BuildResource(ResourceID, "Guest", "image/jpeg", Resources.GuestAvatar, null);

                #region Arena5 Related
                case "C8E0DCF7-F84D-48BD-B76C-4745A9975DCB":
                    return BuildResource(ResourceID, "Arena53d", "text/javascript", Resources.arena_3d, null);
                case "A4B2F8FC-CC06-4FE3-B8A8-7EA7CA7D3D85":
                    return BuildResource(ResourceID, "Arena5Effects", "text/javascript", Resources.arena_effects, null);
                case "60AA185B-E1F6-47D9-89FB-07ECBCD3E66F":
                    return BuildResource(ResourceID, "Arena5Enemies", "text/javascript", Resources.arena_enemies, null);
                case "C0CEA180-AF06-4A2C-8E29-D14AC155BBD5":
                    return BuildResource(ResourceID, "Arena5Main", "text/javascript", Resources.arena_main, null);
                case "B998B2FB-6447-47DE-9387-A9A6B6DEF0FD":
                    return BuildResource(ResourceID, "Arena5Player", "text/javascript", Resources.arena_player, null);
                case "2BB1237A-7726-4D2F-AD22-C415E3482B5E":
                    return BuildResource(ResourceID, "ArenaWeapons", "text/javascript", Resources.arena_weapons, null);
                case "1FD04B1A-3C12-4B3C-AE67-E2234B9ACEAD":
                    return BuildResource(ResourceID, "Arena5Background", "image/jpeg", Resources.arena5_bg2, null);
                case "3BB609FE-0B99-4802-9BA2-6330B60865A4":
                    return BuildResource(ResourceID, "Arena5k3d", "text/javascript", Resources.k3d_min, null);
                case "AB6F3168-FA91-47C1-9FC1-FCAAA69C2020":
                    return BuildResource(ResourceID, "Arena5GameLib", "text/javascript", Resources.gamelib, null);
                case "C67C72A1-0479-4DF9-8C1A-BF7EF0E93211":
                    return BuildResource(ResourceID, "Arena5MathLib", "text/javascript", Resources.mathlib_min, null);
                case "FA28E55D-7282-4226-95A7-2FA8D4171BB9":
                    return BuildResource(ResourceID, "Arena5SimpleAI", "text/javascript", Resources.arena_simpleai, null);                
                case "F4F17A0B-B434-4AAD-82C1-36AAA3672EC3":
                    return BuildResource(ResourceID, "Arena5", "image/jpeg", Resources.arena5, null);
                case "BB83CC80-C002-4033-A338-EC4BA4EEECC3":
                    return BuildResource(ResourceID, "arena.css", "text/css", Resources.arena, null);
                // sounds
                case "7E2BC6AE-71EF-43EC-A95B-C3C56A26AF8D":
                    return BuildResource(ResourceID, "bigboom.mp3", "audio/mpeg", Resources.bigboom, null);
                case "55327D16-B552-40BF-AED2-28706E6AA333":
                    return BuildResource(ResourceID, "explosion1.mp3", "audio/mpeg", Resources.explosion1, null);
                case "E986F7DD-135C-481B-8DFF-B79091DD459B":
                    return BuildResource(ResourceID, "explosion2.mp3", "audio/mpeg", Resources.explosion2, null);
                case "96BF143D-F4A5-49D5-AA7E-D70B1364C77D":
                    return BuildResource(ResourceID, "explosion3.mp3", "audio/mpeg", Resources.explosion3, null);
                case "03F82ED1-DFEE-49AD-94A5-311F07038AD9":
                    return BuildResource(ResourceID, "explosion4.mp3", "audio/mpeg", Resources.explosion4, null);
                case "65A354D8-1DF4-4982-BE80-E0863899B081":
                    return BuildResource(ResourceID, "hiss1_wav.mp3", "audio/mpeg", Resources.hiss1_wav, null);
                case "870640BA-A6DB-4418-907F-BE40EF1174B7":
                    return BuildResource(ResourceID, "hiss2_wav.mp3", "audio/mpeg", Resources.hiss2_wav, null);
                case "4B06BC22-51D6-454D-86FB-4F5C51D83E10":
                    return BuildResource(ResourceID, "laser_wav.mp3", "audio/mpeg", Resources.laser_wav, null);
                case "C3B09623-4B7B-46CD-962E-70794CD10547":
                    return BuildResource(ResourceID, "pewpew3_wav.mp3", "audio/mpeg", Resources.pewpew3_wav, null);
                case "65C82A3F-D013-4D55-BEA5-AF6E270AB9E2":
                    return BuildResource(ResourceID, "pickup4_wav.mp3", "audio/mpeg", Resources.pickup4_wav, null);
                #endregion

                #region defaultAvatar
                case "87c981c4-07fc-42d3-97ee-ab0b4676cea0":
                    return BuildResource(ResourceID, "defaultAvatar.png", "image/png", Resources.DefaultGame, null);
                #endregion
            }

            throw new Exception("As this is temporary and data is static - this should not happen");
        }

        private Model.Resource BuildResource(Guid id, string name, string contentType, byte[] content, DateTime? created)
        {
            //TypeConverter tc = TypeDescriptor.GetConverter(typeof(byte[]));

            return new Model.Resource
            {
                ContentType = contentType,
                Name = name,
                Bytes = content,
                ID = id,
                CreatedDate = created ?? new DateTime(2012, 05, 05)
                //Bytes = File.ReadAllBytes(@"C:\Users\chilberto\Documents\Visual Studio 2010\Projects\AzureGames\AzureGames.Web\GameResources\Amazons\1\" + name)
            };
        }

        private Model.Resource BuildResource(Guid id, string name, string contentType, string content, DateTime? created)
        {            
            UTF8Encoding utf = new UTF8Encoding();

            return new Model.Resource
            {
                ContentType = contentType,
                Name = name,                              
                Bytes = utf.GetBytes(content),
                ID = id,
                CreatedDate = created ?? new DateTime(2012, 05, 05)
            };            
        }
        
        private Model.Resource BuildResource(Guid id, string name, string contentType, Bitmap content, DateTime? created)
        {            
            TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap));

            return new Model.Resource
            {
                ContentType = contentType,
                Name = name,                              
                Bytes = (byte[]) tc.ConvertTo(content, typeof(byte[])),
                ID = id,
                CreatedDate = created ?? new DateTime(2012, 05, 05)
                //Bytes = File.ReadAllBytes(@"C:\Users\chilberto\Documents\Visual Studio 2010\Projects\AzureGames\AzureGames.Web\GameResources\Amazons\1\" + name)
            };
        }

        public void CreateResource(Model.Resource resource)
        {
            throw new NotImplementedException();
        }

        public void UpdateResource(Model.Resource resource)
        {
            throw new NotImplementedException();
        }

        public bool DeleteResource(Guid ResourceID)
        {
            throw new NotImplementedException();
        }
    }
}
